var content = document.querySelector('.content');

content.addEventListener('mouseenter', function() {
  content.style.transition = 'background-color 0.3s';
  content.style.backgroundColor = 'rgba(100,100,100,0.5)'; // 将透明度更改为 0.5，使背景色加深
});

content.addEventListener('mouseleave', function() {
  content.style.transition = 'background-color 0.3s';
  content.style.backgroundColor = 'rgba(100,100,100,0.2)'; // 将透明度恢复为 0.2，使背景色变浅
});

var yesBtn = document.getElementById('yesBtn');
var backBtn = document.getElementById('backBtn');

yesBtn.addEventListener('click', function() {
//  var name = document.getElementById('name').value;
//  var sex = document.getElementById('sex').value;
//  var birth = document.getElementById('birth').value;
  var phone = document.getElementById('phone').value;
  var email = document.getElementById('email').value;
//  var major = document.getElementById('major').value;
//  var clas = document.getElementById('clas').value;

//  console.log(name);
//  console.log(sex);
//  console.log(birth);
  console.log(phone);
  console.log(email);
//  console.log(major);
//  console.log(clas);

//  var confirmLogout = confirm("确定要修改吗？");
//  if (confirmLogout) {
    // 用户点击了确认按钮
    // 编写退出登录的操作


  // 这里可以编写后端调用的代码，验证用户名和密码是否匹配数据库
  $.ajax({
    url: '/management/changeservlet/teaChange',
    method: 'POST',
    data: {
//      name: name,
//      sex: sex,
//      birth: birth,
      phone: phone,
      email: email
//      major: major,
//      id:id
    },
    success: function(response) {
        console.log("111");
      window.location.href = "teainfo.html";
    },
    error: function(xhr, status, error) {
      // 处理错误
      console.log(error);
    }

  });
//  }else {
//
//
//              }
});

backBtn.addEventListener('click', function() {
  // 返回上一个页面的操作
  window.history.back();
});

document.addEventListener("DOMContentLoaded", function() {

  const nameElement = document.querySelector('.info-text[name="name"]');
  const genderElement = document.querySelector('.info-text[name="gender"]');
  const birthdateElement = document.querySelector('.info-text[name="birthdate"]');

  const majorElement = document.querySelector('.info-text[name="major"]');
  const idElement = document.querySelector('.info-text[name="id"]');

  $.ajax({
    url: '/management/menuservlet/teaMenu',
    method: 'POST',
    data: {
      username: "孔老师"
    },
    success: function(response) {
//      console.log(response['name']);
//      console.log(response[1]);
      console.log(response);
      console.log(response.data);
//      nameElement.textContent = response['name'];
//      genderElement.textContent = response['gender'];
//      birthdateElement.textContent = response['birthdate'];
//      phoneElement.textContent = response['phone'];
//      emailElement.textContent = response['email'];
//      majorElement.textContent = response['major'];
//      idElement.textContent = response['id'];
      var data = response.data;
      // 将数据数组赋值给相应的元素
      nameElement.textContent = data[0];
      genderElement.textContent = data[1];
      birthdateElement.textContent = data[2];

      majorElement.textContent = data[5];
      idElement.textContent = data[6];
    }
  });
});

document.addEventListener("DOMContentLoaded", function() {

  const nameElement = document.querySelector('.info-text[name="name"]');
  const genderElement = document.querySelector('.info-text[name="gender"]');
  const birthdateElement = document.querySelector('.info-text[name="birthdate"]');

  const majorElement = document.querySelector('.info-text[name="major"]');
  const idElement = document.querySelector('.info-text[name="id"]');

  $.ajax({
    url: '/management/menuservlet/teaMenu',
    method: 'POST',
    data: {
      username: "孔老师"
    },
    success: function(response) {
//      console.log(response['name']);
//      console.log(response[1]);
      console.log(response);
      console.log(response.data);
//      nameElement.textContent = response['name'];
//      genderElement.textContent = response['gender'];
//      birthdateElement.textContent = response['birthdate'];
//      phoneElement.textContent = response['phone'];
//      emailElement.textContent = response['email'];
//      majorElement.textContent = response['major'];
//      idElement.textContent = response['id'];
      var data = response.data;
      // 将数据数组赋值给相应的元素
      nameElement.textContent = data[0];
      genderElement.textContent = data[1];
      birthdateElement.textContent = data[2];

      majorElement.textContent = data[5];
      idElement.textContent = data[6];
    }
  });
});